package com.erpanderp.wam.tm.view;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import com.erpanderp.wam.tm.model.entity.RecruitmentRequest;
import com.erpanderp.wam.tm.model.service.RRFDAO;
import com.erpanderp.wam.usm.model.entity.user.WAMUser;
import com.erpanderp.wam.util.CommonLookup;

@ManagedBean
@ViewScoped
public class ShortListRRFslistBean implements Serializable{

	private static final long serialVersionUID = 1L;
	private HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
	private WAMUser wamUser = (WAMUser) session.getAttribute(CommonLookup.SESSION_ATTRIBUTE_WAMUSER);	

	private List<RecruitmentRequest> recruitmentRequestList = new ArrayList<RecruitmentRequest>();
	
	private RRFDAO rrfDAO = new RRFDAO();
	
	public ShortListRRFslistBean() {
		if (wamUser != null) {			
			recruitmentRequestList = rrfDAO.getRRFSByEmployeeId(wamUser.getEmployee().getEmployeeId());
		}else{
			System.out.println("WAM USER NULL=======");
		}		
	}
	 //SHORT PROFILES ACTION
	 public String shortListRRFAction() {
		 try{
			  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			  
			  //String EMPID = params.get("employeeId");
			  String rrfCode = params.get("rrfCode");
			 // String recruiterId = params.get("recruiterCode");
			  
			 // FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("EMPID", EMPID);
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);		  
			  //FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("recruiterId", recruiterId);
			  
			//  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/managershortlistprofiles.html?EMPID="+EMPID+"&rrfCode="+rrfCode+"&recruiterId="+recruiterId);
			  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/managershortlistprofiles.html?rrfCode="+rrfCode);
			
		  }catch (Exception e) {
			  e.printStackTrace();
		 }
		 return "managershortlistprofiles";
	}
	 
	 //View RRF FORM 
	 public String viewRRFAction() {
		 try{
			  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
			  
			  String EMPID = params.get("employeeId");
			  String rrfCode = params.get("rrfCode");
			  String recruiterId = params.get("recruiterCode");
			  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("EMPID", EMPID);
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);		  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("recruiterId", recruiterId);
			  
			  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/viewRRFByReportingManager.html?EMPID="+EMPID+"&rrfCode="+rrfCode+"&recruiterId="+recruiterId);
			
		  }catch (Exception e) {
			  e.printStackTrace();
		 }
		 return "viewRRFByReportingManager";
	}
	 
	 //SCHEDULE FIRST LEVEL
	 public String scheduleRRFsAction() {
		 try{
			  Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

			  String rrfCode = params.get("rrfCode");
			  String activity=params.get("activity");
			  
			  System.out.println("activity::::::::::"+activity);
			  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("rrfCode", rrfCode);		  
			  FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("activity", activity);
			  
			  if(activity.equals("ScheduleByRecruiter")){
				FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/scheduleinterviews.html?rrfCode="+rrfCode+"&activity="+activity);
			  }else{
				  System.out.println(":::::::::::;ACTION ELSE BLOCK::::::::::");
				  FacesContext.getCurrentInstance().getExternalContext().redirect("/wam/tm/scheduleinterviews.html?rrfCode="+rrfCode+"&activity="+activity);
			  }
		  }catch (Exception e) {
			  e.printStackTrace();
		 }
		 return "scheduleinterviews";
	}
	 
	//GENERATE SETTERS AND GETTERS
	public WAMUser getWamUser() {
		return wamUser;
	}

	public void setWamUser(WAMUser wamUser) {
		this.wamUser = wamUser;
	}

	public List<RecruitmentRequest> getRecruitmentRequestList() {
		return recruitmentRequestList;
	}

	public void setRecruitmentRequestList(List<RecruitmentRequest> recruitmentRequestList) {
		this.recruitmentRequestList = recruitmentRequestList;
	}

	public RRFDAO getRrfDAO() {
		return rrfDAO;
	}

	public void setRrfDAO(RRFDAO rrfDAO) {
		this.rrfDAO = rrfDAO;
	}

}
